package com.smarthealthring.mm.ui.activity;

import android.animation.Animator;
import android.animation.ObjectAnimator;
import android.animation.ValueAnimator;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.content.ContextCompat;
import android.widget.TextView;

import com.jakewharton.rxbinding2.view.RxView;
import com.smarthealthring.mm.R;
import com.smarthealthring.mm.base.BaseActivity;
import com.smarthealthring.mm.base.IPresenter;
import com.smarthealthring.mm.utils.SizeUtils;
import com.smarthealthring.mm.utils.statusbar.StatusBarCompat;
import com.trello.rxlifecycle2.android.ActivityEvent;

import org.reactivestreams.Subscription;

import java.util.concurrent.TimeUnit;

import butterknife.BindView;
import io.reactivex.Flowable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.functions.Consumer;
import io.reactivex.functions.Function;

/**
 * 倒计时页面
 */
public class CountDownActivity extends BaseActivity {

    @BindView(R.id.tv_counttime)
    TextView mTvCountTime;

    @Override
    protected void initComToolBar() {

    }

    @Override
    protected int getLayout() {
        return R.layout.act_countdown;
    }

    @Override
    protected void initEventAndData(@Nullable Bundle savedInstanceState) {
        StatusBarCompat.setStatusBarColor(mContext, ContextCompat.getColor(mContext,R.color.title_green));
        startDropAnim();
    }

    private void startDropAnim() {
        ObjectAnimator animator = ObjectAnimator.ofFloat(mTvCountTime, "translationY", SizeUtils.dp2px(mContext, 400));
        animator.setRepeatCount(3);
        animator.setDuration(1000);
        animator.setRepeatMode(ValueAnimator.RESTART);
        animator.start();
        animator.addListener(new Animator.AnimatorListener() {
            @Override
            public void onAnimationStart(Animator animation) {

            }

            @Override
            public void onAnimationEnd(Animator animation) {
                startActivity(new Intent(mContext,CountTourActivity.class));
                finish();
            }

            @Override
            public void onAnimationCancel(Animator animation) {

            }

            @Override
            public void onAnimationRepeat(Animator animation) {
                switch (mTvCountTime.getText().toString()){
                    case "3":
                        mTvCountTime.setText("2");
                        break;
                    case "2":
                        mTvCountTime.setText("1");
                        break;
                    case "1":
                        mTvCountTime.setText("GO");
                        break;
                }
            }
        });
    }

    @Override
    protected IPresenter createPresenter() {
        return null;
    }
}
